/**
 * Class CsvOrderUploadModule.
 * 
 * @author Flavio Duboc
 */
CsvOrderUploadModule.inherits(OrderUploadModule);
function CsvOrderUploadModule() {
	this.params = {
			'uploadOrdersRequestPath' : 'uploadCSVOrder',
			'searchUploadTasksRequestPath' : 'getOrderTasks',
			'downloadUploadTaskReportRequestPath' : 'downloadOrderTaskReport'
		};
	this.parentConstructor(OrderUploadModule);
}

CsvOrderUploadModule.neededRoles = ['UPLOAD_ORDER_CSV'];

CsvOrderUploadModule.prototype.fillJQ = function(jQ) {
	var that = this;
	
	this.setParams(this.params);
	// Title
	jQ.append($('<h4>' + I18n.get('order.upload.title') + '</h4>'));
	
	// Csv Order upload form
	var uploadForm = $('<div class="cropbottom well"></div>');
	jQ.append(uploadForm);
	var fileUpload = $('<div class="fileUpload"></div>');
	uploadForm.append(fileUpload);
	fileUpload.append(this.inputFileModule.buildJQ());
	fileUpload.append($('<span class="btn send">' + I18n.get('send') + '</span>').click(function() {
		that.uploadOrders();
	}));
	
	// Csv Order search form
	jQ.append($('<h5>' + I18n.get('order.upload.search') + '</h5>'));
	var searchForm = $('<div class="well row-fluid"></div>');
	jQ.append(searchForm);
	
	var columnLeft = $('<div class="span6"></div>');
	columnLeft.append(this.inputStartDate.buildJQ());
	columnLeft.append(this.inputReferrer.buildJQ());
	var columnRight = $('<div class="span6"></div>');
	columnRight.append(this.inputEndDate.buildJQ());
	columnRight.append(this.inputStatus.buildJQ());
	searchForm.append(columnLeft).append(columnRight);

	// Buttons
	var buttonRow = $('<div class="btn-row"></div>');
	searchForm.append(buttonRow);
	
	var buttonSearch = $('<div class="btn search">' + I18n.get('search') + '</div>');
	buttonSearch.click(function() { that.searchUploadTasks(); });
	buttonRow.append(buttonSearch);
	
	// Csv Order upload table
	var result = $('<div class="result"></div>');
	jQ.append(result);
	result.append($('<br/>'));
	result.append($('<h5>' + I18n.get('order.upload.list') + '</h5>'));
	if (this.uploadTable.objectMap.size == 0) {
		result.hide();
	}
	result.append(this.uploadTable.buildJQ());
	
	// Launches the search
	this.searchUploadTasks();
};